package com.globalLogic.gps;

import java.util.ArrayList;
import java.util.List;

import com.globalLogic.geometry.Point;
import com.globalLogic.gps.graph.MapGraph;
import com.globalLogic.gps.graph.algorithms.Dijkstra;
import com.globalLogic.gps.maps.elements.Road;
import com.globalLogic.gps.stalite.IStalite;
import com.globalLogic.gps.view.GPSView;
import com.globalLogic.mocks.RaodMock;
import com.globalLogic.mocks.SateliteMock;

public class GPS {

	private boolean dirty = true;
	private boolean asphalt = true;
	
	private List<Road> listRoad;
	private IStalite satelite;
	private MapGraph map;
	private GPSView view;
	

	public void on()
	{
		satelite = SateliteMock.getInstance();
		listRoad = RaodMock.getListRoads();
		map = new MapGraph(listRoad);
		map.setAlgorithm(new Dijkstra());
		view = new GPSView(map);
		
		
	}
	
	public String  minimumRoute(Point from, Point to)
	{
		map.recalculate(filterRoad());
		return map.minimumRoute(from, to);
	}

	
	
	public Point getPosition()
	{
		return getSatelite().getPosition();
	}



	public boolean isDirty() {
		return dirty;
	}

	public void setDirty(boolean dirty) {
		this.dirty = dirty;
	}

	public boolean isAsphalt() {
		return asphalt;
	}

	public MapGraph getMap() {
		return map;
	}
	private List <Road> filterRoad()
	{
		// Aca pienso poner un poco de java 8
		
		List <Road> result = new ArrayList<Road>();
		for (Road road : getListRoad()) {
			if ((isDirty() && road.isDirty())||(isAsphalt() && road.isAsphalt()))
				result.add(road);
		  }
		
		return result;
	}

	private List<Road> getListRoad() {
		return listRoad;
	}

	private IStalite getSatelite() {
		return satelite;
	}
}
